Skip to content

Add POSIX-TZ support#31

Open
mulderr wants to merge 6 commits intonilcons:masterfrom
mulderr:master
Open

Add POSIX-TZ support#31
mulderr wants to merge 6 commits intonilcons:masterfrom
mulderr:master

Conversation

@mulderr
Copy link

@mulderr mulderr commented Nov 16, 2021

This is a big change. Submitting for review as a work in progress. Parsing seems to work. Most functions seem to be updated to use rules when time is past last explicitly stored transition. Implementation (except parsing) is mostly translated from musl libc, which is licensed under MIT so I hope that is fine.

As an example:

% env TZ=Europe/Warsaw date -d '2038-07-01 UTC'
Thu Jul  1 02:00:00 AM CEST 2038

Before:

> tz <- loadTZFromDB "Europe/Warsaw"
> timeZoneForUTCTime tz (UTCTime (fromGregorian 2038 4 1) 0)
CET

After:

> timeZoneForUTCTime tz (UTCTime (fromGregorian 2038 4 1) 0)
CEST

TODO

  • update localToPosix (and localTimeToUTCFull if needed)
  • add tests

@mulderr
Copy link
Author

mulderr commented Nov 17, 2021

Hmm... checkTimeZone64 reveals that glibc miscalculates time zones for posix timestamps above around 2^47. I've limited tests to values below that.

% env TZ=America/Los_Angeles date -d '5881580-7-1 00:00 UTC'
Mon Jun 30 05:00:00 PM PDT 5881580
% env TZ=America/Los_Angeles date -d '5881581-7-1 00:00 UTC'
Tue Jun 30 04:00:00 PM PST 5881581

> logBase 2 $ fromIntegral $ utcTimeToInt64 $ UTCTime (fromGregorian 5881581 7 1) 0
47.398743929757934

For reference, 1st July should always be in PDT according to the rule:

> (fmap renderPosixTz . _tzPosixTz) <$> loadTZFromDB "America/Los_Angeles"
Just "PST8PDT,M3.2.0,M11.1.0"

@klao
Copy link
Member

klao commented Nov 17, 2021

Thanks a lot!

I started working on this about a year ago, but for various reasons haven't finished. 😅 Do you mind if I cherry-pick from your code and merge it with whatever I have?

Also, I'm very busy this week, so I'll try to get to this sometime next week!

@mulderr
Copy link
Author

mulderr commented Nov 17, 2021

Awesome! I wasn't sure how to deal with localToPosix so uh... yeah go ahead :).

I just pushed test tweaks I was working on but I'll hold off with any more changes for now to give you time to glue things together.

@mulderr
Copy link
Author

mulderr commented Nov 18, 2021

... except I think it would be best not to depend on attoparsec so at the cost of additional approx 100 lines of code I've inlined what we need to parse POSIX-TZ. That's in case you don't already have something better of course ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants